import { mock } from "mockjs";

const prefix = import.meta.env.VITE_BASE_URL + "/article";
// 精彩内容
mock(prefix + "/exciting", () => {
  const res = mock({
    success: "请求成功",
    code: 200,
    "data|12": [{
      "id": "@id",
      "bg": "@image",
      "title": "@ctitle",
      user: {
        "id": "@id",
        "username": "@cname",
        nickname: "@cname",
        desc: "@csentence",
        avatar: "@image",
      },
      createTime: "@DATETIME('MM月dd日')",
      desc: "@csentence",
    }]
  })
  return res;
})
//推荐专区
mock(prefix + "/recommended", () => {
  const res = mock({
    success: "请求成功",
    code: 200,
    "data|6": [{
      "id": "@id",
      "bg": "@image",
      "title": "@ctitle",
      user: {
        "id": "@id",
        "username": "@cname",
        nickname: "@cname",
        desc: "@csentence",
        avatar: "@image",
      },
      createTime: "@DATETIME('MM月dd日')",
      desc: "@csentence",
    }]
  })
  return res;
})
// 热门回答
mock(prefix + "/not", () => {
  const res = mock({
    success: "请求成功",
    code: 200,
    "data|10": [{
      "id": "@id",
      "title": "@ctitle(10,18)",
      createTime: "@DATETIME('MM月dd日')",
    }]
  })
  return res;
})

//分页切换 /${type}/page/${current}/${size}
mock(/\/article\/.*\/page/, (option) => {
  const vals = option.url.split("\/");
  console.log();


  // 生成数字 
  const total = mock("@integer(100, 1000)");

  const res = mock({
    success: "请求成功",
    code: 200,
    "data|6":
    {
      total,
      current: Number.parseInt(vals[vals.length - 2]),
      pagesize: Number.parseInt(vals[vals.length - 1]),
      "data|10": [{
        "id": "@id",
        "title": "@ctitle",
        user: {
          "id": "@id",
          "username": "@cname",
          nickname: "@cname",
          desc: "@csentence",
          avatar: "@image",
        },
        answerCount: "@integer(1,1000)",
        readCount: "@integer(1,1000)",
        "tags|2-7": [{
          id: "@id",
          tagName: "@cname",
          avatar: "@img",
        }],
        createTime: "@DATETIME('MM月dd日')",
        desc: "@csentence",
      }],
    }
  })
  return res;
})

// 问答详情
mock(/\/article\/.*\/details/, () => {
  const res = mock({
    success: "请求成功",
    code: 200,
    "data":
    {
      "id": "@id",
      "title": "@ctitle",
      user: {
        "id": "@id",
        "username": "@cname",
        nickname: "@cname",
        desc: "@csentence",
        avatar: "@image",
        fansCount: "@integer(500,10000)",
        reputationCount: "@integer(500,10000)",
        isInterest: "@boolean"
      },
      content: "@title",
      createTime: "@DATETIME('MM月dd日')",
      liveCount: "@integer(1,1000)",
      "tags|2-7": [{
        id: "@id",
        tagName: "@cname",
        avatar: "@img",
      }],
      readCount: "@integer(1,1000)",
      interest: "@integer(1,1000)",//多少人关注
      collect: "@boolean",//自己是否关注
    }
  })
  return res;
})






